<?php

declare(strict_types=1);

use app\middleware\{AuthTokenMiddleware, PermissionMiddleware};
use module\user\middleware\AuthTokenMiddleware as UserAuthTokenMiddleware;
use think\facade\Route;

Route::group('admin', function () {
    Route::get('config$', '\module\chat\controller\admin\Config@options');
    Route::post('config$', '\module\chat\controller\admin\Config@submit');
    Route::get('message', '\module\chat\controller\admin\Message@index');

    Route::resource('category', '\module\chat\controller\admin\Category');
    Route::resource('assistant', '\module\chat\controller\admin\Assistant');
    Route::resource('visrole', '\module\chat\controller\admin\Visrole');
    Route::resource('message', '\module\chat\controller\admin\Message')->except(['save', 'create', 'edit']);
})->middleware([
    AuthTokenMiddleware::class, // 登录校验
    PermissionMiddleware::class // 权限校验
]);

Route::group('', function () {
    Route::group('index', function () {
        Route::get('channels', '\module\chat\controller\Index@channels');
        Route::get('config', '\module\chat\controller\Index@config');
    });

    Route::resource('unlimited', '\module\chat\controller\Unlimited')
        ->only(['index', 'read', 'save', 'update', 'delete'])
        ->middleware('user:login');

    Route::group('message', function () {
        Route::post(':id/clearContext', '\module\chat\controller\Message@clearContext');
        Route::delete(':id/delete', '\module\chat\controller\Message@Delete');
        Route::post('send', '\module\chat\controller\Message@send');
        Route::delete('deleteAll', '\module\chat\controller\Message@deleteAll');
        Route::get('receive', '\module\chat\controller\Message@receive');
        Route::get('receiveStream', '\module\chat\controller\Message@receiveStream');
        Route::post(':id/cancel', '\module\chat\controller\Message@cancel');
        Route::get('history', '\module\chat\controller\Message@history');
    })->middleware('user:login');

    Route::group('assistant', function () {
        Route::get('$', '\module\chat\controller\Assistant@index');
        Route::get('categories', '\module\chat\controller\Assistant@categories');
        Route::get(':id$', '\module\chat\controller\Assistant@read');
        Route::rule(':id/favorite$', '\module\chat\controller\Assistant@favorite', 'post|delete')
            ->middleware('user:login');
    });

    Route::group('visrole', function () {
        Route::get('$', '\module\chat\controller\Visrole@index');
        Route::get('categories$', '\module\chat\controller\Visrole@categories');
        Route::get(':id$', '\module\chat\controller\Visrole@read');
        Route::rule(':id/favorite$', '\module\chat\controller\Visrole@favorite', 'post|delete')
            ->middleware('user:login');
    });
})->middleware('user:auth');